package com.atXiao.滑动窗口;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Demo {

    public static String maxValue(String input) {

        String[] arrs = input.split(",");
        if (arrs.length>25){
            throw new RuntimeException();
        }
        PriorityQueue<String> queue = new PriorityQueue<>(new Comparator<String>() {


            @Override
            public int compare(String o1, String o2) {
                int l1 = o1.length();
                int l2 = o2.length();
                int min = Math.min(l1, l2);

                char[] chars1 = o1.toCharArray();
                char[] chars2 = o2.toCharArray();

                int tem = 0;
                while (tem < min) {
                    char c1 = chars1[tem];
                    char c2 = chars2[tem];
                    if (c1 != c2) {
                        return c2 - c1;
                    }
                    tem++;
                }
                return l1 - l2;
            }
        });

        for (int i = 0; i < arrs.length; i++) {
            queue.offer(arrs[i]);
        }

        StringBuffer sb = new StringBuffer();
        while (!queue.isEmpty()) {
            sb.append(queue.poll());
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            String input = in.next();
            String maxValue = maxValue(input);
            System.out.println(maxValue);
        }

    }

}
